#ifndef COMMAND_SENDER_THREAD_H
#define COMMAND_SENDER_THREAD_H

#include <cstdio>
#include <QThread>
#include <iostream>
#include <fstream>
#include <sstream>

#include "Action.h"
#include "UDPSocket.h"

class CommandSenderThread : public QThread
{
    Q_OBJECT
public:
    void run()
    {
        while(1)
        {

        }
        //this->exec();
    }

    void sendKick(Action a)
    {
        stringstream init_string;
        init_string << "(kick " << a.getPower() << " " << a.getDir() << ")";
        UDPSocket::instance().Send(init_string.str().c_str());

        //printf("Sent command: %s\n", init_string.str().c_str());
    }

    void sendTurn(Action a)
    {
        stringstream init_string;
        init_string << "(turn " << a.getDir() << ")";
        UDPSocket::instance().Send(init_string.str().c_str());

        //printf("Sent command: %s\n", init_string.str().c_str());
    }

    void sendDash(Action a)
    {
        stringstream init_string;
        init_string << "(dash " << a.getPower() << ")";
        UDPSocket::instance().Send(init_string.str().c_str());

        //printf("Sent command: %s\n", init_string.str().c_str());
    }

public slots:
    void sendAction(Action a)
    {
        switch(a.getType())
        {
        case Kick: sendKick(a); break;
        case Turn: sendTurn(a); break;
        case Dash: sendDash(a); break;
        }
    }
};

#endif // COMMAND_SENDER_THREAD_H
